﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraBars;
using DTO;
using BUS;

namespace HOTEL_MANAGEMENT
{
    public partial class frmGiamDoc : DevExpress.XtraBars.Ribbon.RibbonForm
    {
        public frmGiamDoc()
        {
            InitializeComponent();
        }
        public void GoiForm(Form frm)
        {
            frm.MdiParent = this;
            frm.Dock = DockStyle.Fill;
            frm.Activate();
            frm.WindowState = FormWindowState.Maximized;
            frm.Show();
        }
        public void GoiFormDangNhap(Form frm)
        {
            frm.Dock = DockStyle.Fill;
            //frm.Activate();
            frm.WindowState = FormWindowState.Minimized;
            frm.Show();
        }
        
        private int TinhTongLoaiPhong(int MaLoaiPhong)
        {
            int dem = 0;
            List<CLOAIPHONGDTO> lp = CLOAIPHONGBUS.LayDanhSachLoaiPhong();
            for (int i = 0; i < lp.Count; i++)
            {
                if (lp[i].Duyet == true && lp[i].MaLoaiPhong == MaLoaiPhong)
                    dem++;
            }
            return dem;
        }
        private int MaLoaiPhong(int MaPhong)
        {
            List<CPHONGDTO> ph = CPHONGBUS.LayDanhSachPhong();
            
            for (int i = 0; i < ph.Count; i++)
            {
                if (ph[i].MaPhong == MaPhong)
                    return ph[i].MaLoaiPhong;
            }
            return 0;
        }
      
        private void btnBaoCaoTheoLoaiPhong_ItemClick(object sender, ItemClickEventArgs e)
        {
            //List<CHOADONDTO> hd = CHOADONBUS.LayDanhSachHoaDon();
            //List<CLOAIPHONGDTO> lp = CLOAIPHONGBUS.LayDanhSachLoaiPhong();
            //List<CPHIEUTHUEDTO> pt = CPHIEUTHUEBUS.LayDanhSachPhieuThue();
           
            //for (int i = 0; i < lp.Count; i++) 
            //{
            //    if (lp[i].Duyet == true)
            //    {
            //        int TongLP = TinhTongLoaiPhong(lp[i].MaLoaiPhong);
            //        int SoNgayThue = 0;
            //        Double doanhthu = 0;
            //        int MaHoaDon = 0;
            //        for (int j = 0; j < hd.Count; j++)
            //        {
            //            if (hd[j].TinhTrang == false)
            //            {
            //                for (int t = 0; t < pt.Count; t++)
            //                {

            //                    if (pt[t].MaHoaDon == hd[j].MaHoaDon && pt[t].NgayBatDau.Month == DateTime.Today.Month && pt[t].NgayBatDau.Year == DateTime.Today.Year)
            //                    {
            //                        int MaLP = MaLoaiPhong(pt[t].MaPhong);

            //                        if (MaLP == lp[i].MaLoaiPhong)
            //                        {
            //                            SoNgayThue += hd[j].SoNgayThue;
            //                            doanhthu += hd[j].TriGia;
            //                            MaHoaDon = pt[t].MaHoaDon;
            //                        }
            //                    }
            //                }
            //            }
            //        }
            //        if (SoNgayThue != 0)
            //        {
            //            CDOANHTHULOAIPHONGDTO dtlp = new CDOANHTHULOAIPHONGDTO();
            //            dtlp.DoanhThu = doanhthu;
            //            dtlp.MaHoaDon = MaHoaDon;
            //            dtlp.MaLoaiPhong = lp[i].MaLoaiPhong;
            //            dtlp.NgayLapBaoCao = DateTime.Today;
            //            dtlp.TyLe = 25.5;
            //            CDOANHTHULOAIPHONGBUS.ThemDoanhThuLoaiPhong(dtlp);
            //        }
            //    }
                
           // }    
            GoiForm(SGD_BaoCaoTheoLoaiPhong.getInstance().Layfrm());
          
        }

        private void btnBaoCaoMatDoPhong_ItemClick(object sender, ItemClickEventArgs e)
        {
            GoiForm(SGD_BaoCaoTheoMatDosuDung.getInstance().Layfrm());
        }

        private void btnHeSoLoaiKhach_ItemClick(object sender, ItemClickEventArgs e)
        {
            GoiForm(SQT_thayDoiHeSoLoaiKhach.getInstance().Layfrm());
        }


        private void btnDonGiaLoaiPhong_ItemClick(object sender, ItemClickEventArgs e)
        {
            SQT_thayDoiDonGiaCacLoaiPhong.getInstance().Layfrm().Hide();
            GoiForm(SQT_thayDoiDonGiaCacLoaiPhong.getInstance().Layfrm());
        }
        private void ribbonMain_SelectedPageChanging(object sender, DevExpress.XtraBars.Ribbon.RibbonPageChangingEventArgs e)
        {
            if (e.Page.KeyTip == "D")
            {
                SGD_DuyetQuydinh.getInstance().Layfrm().Hide();
                GoiForm(SGD_DuyetQuydinh.getInstance().Layfrm());
            }
            else if (e.Page.KeyTip == "DUYET")
            {
                SGD_LapDanhMucPhong.getInstance().Layfrm().Hide();
                GoiForm(SGD_LapDanhMucPhong.getInstance().Layfrm());
            }
            else if (e.Page.KeyTip == "SUA")
            {
                SQT_QuiDinh.getInstance().Layfrm().Hide();
                GoiForm(SQT_QuiDinh.getInstance().Layfrm());
            }
            
        }
        private void btnphongDangThue_ItemClick(object sender, ItemClickEventArgs e)
        {
            SGD_LapDanhMucPhong.getInstance().Layfrm().Hide();
            SGD_LapDanhMucPhong.getInstance().NghiepVu = "DangThue";
            GoiForm(SGD_LapDanhMucPhong.getInstance().Layfrm());
        }

        private void btnphongTrong_ItemClick(object sender, ItemClickEventArgs e)
        {

            SGD_LapDanhMucPhong.getInstance().Layfrm().Hide();
            SGD_LapDanhMucPhong.getInstance().NghiepVu = "Trong";
            GoiForm(SGD_LapDanhMucPhong.getInstance().Layfrm());
        }

        private void btndanhMucPhong_ItemClick(object sender, ItemClickEventArgs e)
        {
           
            SGD_LapDanhMucPhong.getInstance().Layfrm().Hide();
            SGD_LapDanhMucPhong.getInstance().NghiepVu = "TatCa";
            GoiForm(SGD_LapDanhMucPhong.getInstance().Layfrm());
        }

        private void btnduyetQuiDinh_ItemClick(object sender, ItemClickEventArgs e)
        {
            GoiForm(SGD_DuyetQuydinh.getInstance().Layfrm());
        }

        private void frmGiamDoc_Load(object sender, EventArgs e)
        {
            lbtenNguoiDung.Text = "Giám đốc : " + SM_DangNhap.getInstance().TenNguoiDung;
        }

        private void lbDangXuat_Click(object sender, EventArgs e)
        {
            if (SM_DangNhap.getInstance().LuuPass == false)
            {
                SM_DangNhap.getInstance().XoaTatCaThongTin();
            }
            SM_DangNhap.getInstance().DangNhapThanhCong = false;

            this.Close();
        }

        private void frmGiamDoc_FormClosing(object sender, FormClosingEventArgs e)
        {
            
              DialogResult result = MessageBox.Show("Bạn có muốn thoát chương trình  hay không", "Thông Báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (result == DialogResult.Yes)
            {
                e.Cancel = false;
                SGD_GiamDoc.Xoa();
                SGD_LapDanhMucPhong.Xoa();
                SGD_DuyetQuydinh.Xoa();
                SGD_BaoCaoTheoMatDosuDung.Xoa();
                SGD_BaoCaoTheoLoaiPhong.Xoa();
                SM_DangNhap.getInstance().Layfrm().Visible = true;
                SM_LoadMain.getInstance().Layfrm().Visible = true;
            }
            else
            {
                e.Cancel = true;
            }            
        }

        private void btnquiDinh_ItemClick(object sender, ItemClickEventArgs e)
        {

            SQT_QuiDinh.getInstance().Layfrm().Hide();
            SQT_QuiDinh.getInstance().NghiepVu = "Trong";
            GoiForm(SQT_QuiDinh.getInstance().Layfrm());
        }

     
    }
}